package com.example.administrator.spritelgs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.spritelgs.R;
import com.example.administrator.spritelgs.bean.BeibaoInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/1.
 */

public class BeibaoAdapter extends BaseAdapter {
    private Context context;
    private List<BeibaoInfo> data;

    private ImageView iv_image;
    private ImageView iv_property;
    private ImageView iv_frame;
    private ImageView iv_rare;
    private ImageView iv_star;
    private TextView tv_level;

    public BeibaoAdapter(Context context, List<BeibaoInfo> data)
    {
        this.context = context;
        if(data != null){
            this.data = data;
        }
        else{
            data = new ArrayList<>();
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null){
            convertView = View.inflate(context, R.layout.item_view_beibao_lv,null);
        }
        //取出数据
        BeibaoInfo bean = data.get(position);
        //取出单元格布局中的控件
        iv_image = (ImageView)convertView.findViewById(R.id.iv_image);
        iv_property = (ImageView)convertView.findViewById(R.id.iv_property);
        iv_frame = (ImageView)convertView.findViewById(R.id.iv_frame);
        iv_rare = (ImageView)convertView.findViewById(R.id.iv_rare);
        //iv_star = (ImageView)convertView.findViewById(R.id);
        tv_level = (TextView) convertView.findViewById(R.id.tv_level);

        iv_image.setImageResource(bean.getImage());
        iv_property.setImageResource(bean.getProperty());
        iv_frame.setImageResource(bean.getFram());
        iv_rare.setImageResource(bean.getRare());
        tv_level.setText(bean.getLevel());

        return convertView;
    }
}
